# Copyright (C) 2019 Lucian Cristian <lucian.cristian@gmail.com>
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.

include $(TOPDIR)/rules.mk

PKG_NAME:=libxcb
PKG_VERSION:=1.13.1
PKG_RELEASE:=1

PKG_SOURCE_URL:=https://xcb.freedesktop.org/dist/
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_MD5SUM:=f33cdfc67346f7217a9326c0d8679975

PKG_BUILD_DEPENDS:=xcb-proto
PKG_BUILD_PARALLEL:=1
PKG_INSTALL:=1

include $(INCLUDE_DIR)/package.mk

define Package/libxcb
  SECTION:=libs
  CATEGORY:=Libraries
  DEPENDS:=+libxau +libxdmcp
  TITLE:=X11 client-side library
  URL:=https://xcb.freedesktop.org
endef

TARGET_CFLAGS += -std=gnu99
TARGET_LDFLAGS += -Wl,--gc-sections,--as-needed

CONFIGURE_ARGS += \
  --prefix=/usr \
  --enable-xkb \
  --enable-xinput \
  --without-doxygen \
  --disable-devel-docs

define Build/Prepare
	$(call Build/Prepare/Default)
	$(SED) \
	 's/pthread-stubs//' \
	 $(PKG_BUILD_DIR)/configure
endef

define Build/InstallDev
	$(INSTALL_DIR) \
	  $(1)/usr/include \
	  $(1)/usr/lib

	$(CP) \
	  $(PKG_INSTALL_DIR)/usr/include/* \
	  $(1)/usr/include/

	$(CP) \
	  $(PKG_INSTALL_DIR)/usr/lib/{pkgconfig,*.so*} \
	  $(1)/usr/lib/
endef

define Package/libxcb/install
	$(INSTALL_DIR) \
	  $(1)/usr/lib

	$(CP) \
	  $(PKG_INSTALL_DIR)/usr/lib/*.so* \
	  $(1)/usr/lib/
endef

$(eval $(call BuildPackage,libxcb))
